<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  import resize from './resize'

  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '100%'
      },
      autoResize: {
        type: Boolean,
        default: true
      },
    },
    data() {
      return {
        chart: null
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')
        this.chart.setOption({
          backgroundColor: '#101e44 ',
          tooltip: {
            trigger: 'axis',
            axisPointer: { // 坐标轴指示器，坐标轴触发有效
              type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
            }
          },
          grid: {
            left: '2%',
            right: '2%',
            // bottom: '14%',
            // top: '16%',
            height: '80%',
            containLabel: true
          },
          legend: {// 右边显示的按钮
            data: ['在线个数', '离线个数', '报警总数'],
            right: 10,
            top: 12,
            textStyle: {
              color: '#fff',
              fontSize: 16
            },
            itemWidth: 30,
            itemHeight: 15
            // itemGap: 35
          },
          xAxis: {
            type: 'category',
            data: ['2019-11-7', '2019-11-8', '2019-11-9', '2019-11-10', '2019-11-11', '2019-11-12', '2019-11-13', '2019-11-14'],
            axisLine: {
              lineStyle: {
                color: 'white'

              }
            },
            axisLabel: {
              // interval: 0,
              // rotate: 40,
              textStyle: {
                fontFamily: 'Microsoft YaHei'
              }
            }
          },

          yAxis: {
            type: 'value',
            max: '70',
            axisLine: {
              show: false,
              lineStyle: {
                color: 'white'
              }
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: 'rgba(255,255,255,0.3)'
              }
            },
            axisLabel: {}
          },
          'dataZoom': [{
            'show': true,
            'height': 15,
            'xAxisIndex': [
              0
            ],
            bottom: '2%',
            'start': 12,
            'end': 90,
            handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
            handleSize: '110%',
            handleStyle: {
              color: '#d3dee5'

            },
            textStyle: {
              color: '#fff' },
            borderColor: '#90979c'
          }, {
            'type': 'inside',
            'show': true,
            'height': 15,
            'start': 1,
            'end': 35
          }],
          series: [{
            name: '在线个数',
            type: 'bar',
            barWidth: '15%',
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: '#fccb05'
                }, {
                  offset: 1,
                  color: '#f5804d'
                }]),
                barBorderRadius: 12
              }
            },
            data: [60, 55, 56, 60, 64, 65, 60, 58, 59]
          },
          {
            name: '离线个数',
            type: 'bar',
            barWidth: '15%',
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: '#8bd46e'
                }, {
                  offset: 1,
                  color: '#09bcb7'
                }]),
                barBorderRadius: 11
              }

            },
            data: [10, 15, 14, 10, 6, 5, 10, 12, 11]
          },
          {
            name: '报警总数',
            type: 'bar',
            barWidth: '15%',
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: '#248ff7'
                }, {
                  offset: 1,
                  color: '#6851f1'
                }]),
                barBorderRadius: 11
              }
            },
            data: [1, 0, 0, 2, 2, 0, 3, 0, 4]
          }]

        }
        )
      }
    }
  }
</script>

<style scoped>

</style>
